﻿Imports System.Web
Imports System.Web.Services
Imports MeoTom.Core

Public Class CustomUrl
    Implements System.Web.IHttpHandler

    Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        context.Response.ContentType = "text/plain"
        Dim util As New Utilities.Common
        If context.Request.QueryString("action") = "GetUrl" Then
            If context.Request.QueryString("Title").Trim = "" Then
                context.Response.Write("")
            Else
                Dim Title As String = util.utf8_to_ascii(context.Request.QueryString("Title").Trim)
                Dim url As String = Configs.HomeUrl & DateTime.Now.Year.ToString & "/" & DateTime.Now.Month.ToString & "/" & DateTime.Now.Day.ToString & "/<span title=""Click to Edit"" style=""background-color:#FCE04E;"" onclick=""javascript:Util.ShowFormEditUrl('spnTitle');"" id=""spnTitle"">" & Title & "</span>-xxx.htm"
                context.Response.Write("<b>Permalink:</b> " & url)
            End If
        ElseIf context.Request.QueryString("action") = "ReturnUrl" Then
            context.Response.Write(util.NoHTML(context.Request.QueryString("Title").Replace("<b>Permalink:</b>", "")).Replace(Configs.HomeUrl, "/").Replace("-xxx.htm", ""))
        ElseIf context.Request.QueryString("action") = "SetTitle" Then
            If context.Request.QueryString("Title") = "" Then
                context.Response.Write("")
            Else
                context.Response.Write(util.utf8_to_ascii(context.Request.QueryString("Title").Trim))
            End If
        End If
        util = Nothing
    End Sub

    ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class